package com.train.member.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.train.member.po.MemberPO;
import com.train.mybatis.base.MyBaseMapper;

/**
* @author baitiaojun
* @description 针对表【member(会员)】的数据库操作Mapper
* @createDate 2025-02-08 17:28:33
* @Entity generator.domain.Member
*/
public interface MemberMapper extends MyBaseMapper<MemberPO> {

    default boolean existsMemberByMobile(String mobile) {
        LambdaQueryWrapper<MemberPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MemberPO::getMobile, mobile);
        return exists(queryWrapper);
    }

    default boolean addMember(String mobile) {
        MemberPO memberPO = new MemberPO();
        memberPO.setMobile(mobile);
        return insert(memberPO) > 0;
    }

    default Long getIdByMobile(String mobile) {
        LambdaQueryWrapper<MemberPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(MemberPO::getId).eq(MemberPO::getMobile, mobile);
        MemberPO memberPO = selectOne(queryWrapper);
        if (memberPO == null) {
            return null;
        }
        return memberPO.getId();
    }
}




